$ () ->
	_url = "/front/list?"

	screenBmi = () ->
		if $("#bmi").val() != ""
			return "&bmi=" + $("#bmi").val()
		else
			return ""

	screenWeight = () ->
		if $("#weight").val() != ""
			return "&weight=" + $("#weight").val()
		else
			return ""

	screenAge = () ->
		if $("#age").val() != ""
			return "&age=" + $("#age").val()
		else
			return ""
	screenSex = () ->
		if $('input:radio[name="sex"]:checked').val() != "" && $('input:radio[name="sex"]:checked').val() != undefined
			return "&sex=" + $('input:radio[name="sex"]:checked').val()
		else
			return ""

	screenProvince = () ->
		if $("#province_id").val() != ""
			return "&province_id=" + $("#province_id").val()
		else
			return ""

	screenHistory = () ->
		if $("#history").val() != ""
			return "&history=" + $("#history").val()
		else
			return ""

	$(".screen_btn").click (e) ->
		window.location.href = _url + screenBmi() + screenWeight() + screenAge() + screenSex() + screenProvince() + screenHistory()


	$(".confirm_btn").click (e) ->
		_sex = ''
		if $('input:radio[name="sex"]:checked').val() != "" && $('input:radio[name="sex"]:checked').val() != undefined
			_sex = $('input:radio[name="sex"]:checked').val()
		param =
			age: $("#age").val()
			sex: _sex
			weight: $("#weight").val()
			bmi: $("#bmi").val()
			province_id: $("#province_id").val()
			history: $("#history").val()
			name: $("#name").val()
			phone: $("#phone").val()

		$.post "/api/front/submit/create", param, (res) ->
			if res.status.errCode is 0
				alert "提交成功，之后会有医生或者护士打电话给您，请您保持电话畅通"
			else
				alert res.status.message